package com.waypolice.manager.component;

import org.activiti.engine.IdentityService;
import org.activiti.engine.identity.User;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 描述:
 *
 * @author zyp
 * @description 工作流用户与组的内容
 * @create 2019-02-27 13:43
 */
@Component
public class WorkflowIdentityComponent {

    private static final Logger logger = LoggerFactory.getLogger(WorkflowIdentityComponent.class);

    @Autowired
    IdentityService identityService;

    /**
     * @author:zyp
     * @description 保存工作流用户
     * @date: 2019/2/27 13:45
     * @return 
     */
    public void saveUser(String userId,String firstName,String lastName,String password,String email) {
        User user = identityService.createUserQuery().userId(userId).singleResult();
        if(user==null){
            user = identityService.newUser(userId);
        }
        user.setFirstName(firstName);
        user.setLastName(lastName);
        user.setEmail(email);
        if (StringUtils.isNotBlank(password)) {
            user.setPassword(password);
        }
        identityService.saveUser(user);
    }

    /**
     * @author:zyp
     * @description 删除工作流用户
     * @date: 2019/2/27 13:54
     * @return 
     */
    public void deleteUser(String ids) {
        if (!StringUtils.isBlank(ids)) {
            String[] idArray = ids.split("-");
            for (String id : idArray) {
                if (StringUtils.isBlank(id)) {
                    continue;
                }
                identityService.deleteUser(id);
            }
        }
    }

}